package edu.chen.bean;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "category_")
public class Category {
    private int id;
    private String name;
//    private int productSum;
    private Set<Product> productSet;

    /**
     * //@OneToMany是指定一对多的关系映射
     * mappedBy是指在"多"对"一"的依赖属性
     * //@LazyCollection
     */
    @OneToMany(mappedBy = "category",fetch = FetchType.LAZY)
    public Set<Product> getProductSet() {
        return productSet;
    }

    public void setProductSet(Set<Product> productSet) {
        this.productSet = productSet;
    }

    /**
     * //@Transient
     * 该注解意为忽略该属性,即该注解标注的属性不是数据库字段的映射
     */
//    @Transient
//    public int getProductSum() {
//        return productSum;
//    }
//
//    public void setProductSum(int productSum) {
//        this.productSum = productSum;
//    }

    @Override
    public String toString() {
        return "Category{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    /**
     * //@Id
     * 该注解表示被标注的属性映射的是数据库表格中的主键
     * //@GeneratedValue
     * 该注解描述主键生成策略
     */
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    /**
     * //@Basic
     * 每个get方法默认带有该注解,表示属性是数据库字段的映射
     * //@Column
     * 该注解详细描述映射的字段信息
     */
    @Basic
    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
